package com.hiv.controller.wechat;

import com.hiv.common.BaseController;
import com.hiv.common.PageInfo;
import com.hiv.common.WebResponse;
import com.hiv.common.param.page.PageQueryPatientParam;
import com.hiv.mapper.domain.Admin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hiv.mapper.domain.Patient;
import com.hiv.service.PatientService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhanghong
 * @version XcxPatientController.java, v 0.1 2022-09-20 XcxPatientController Exp $$
 */
@RestController
@RequestMapping("/wechat/patient")
@Api(value = "患者模块", tags = {"【小程序端】患者模块"})
public class XcxPatientController extends BaseController {
    @Autowired
    private PatientService patientService;

    @ApiOperation(value = "分页查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<Patient>> pageQuery(HttpServletRequest request, @RequestBody PageQueryPatientParam param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(patientService.pageQuery(null, param));
    }

    @ApiOperation(value = "根据id查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<Patient> getById(HttpServletRequest request, @PathVariable("id") long id) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(patientService.getById(id));
    }

    @ApiOperation(value = "保存", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/save")
    public WebResponse<Boolean> save(HttpServletRequest request, @RequestBody Patient param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(patientService.save(param));
    }

    @ApiOperation(value = "删除", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/delete")
    public WebResponse<Boolean> delete(HttpServletRequest request, @RequestParam String ids) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(patientService.deleteByIds(ids));
    }
}
